import java.sql.*;

public class T220054070558 {
    public static Connection getConn() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/xingong","root","182728");
        return conn;
    }
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection conn = getConn();
        PreparedStatement psmt = null;
        String sql = null;
        //一次向数据表中插入多条记录
        /*sql = "insert into tzy values('2001','张三','计科','22')," +
                                            "('2002','李四','计科','21'),"+
                                            "('2003','王二','会计','22')";
        psmt = conn.prepareStatement(sql);
        int i = psmt.executeUpdate(sql);
        System.out.println("影响了"+i+"行");*/

        //删除数据
        sql = "delete from tzy where 学号=2001";
        psmt = conn.prepareStatement(sql);
        psmt.executeUpdate();

        //修改数据
        sql = "update tzy set 专业='计科' where 姓名='王二'";
        psmt = conn.prepareStatement(sql);
        psmt.executeUpdate();

        //查找数据
        sql = "select * from tzy where 年龄=22";
        psmt = conn.prepareStatement(sql);
        ResultSet rs = psmt.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString("学号")+
                                rs.getString("姓名")+
                                rs.getString("专业")+
                                rs.getInt("年龄"));
        }
    }
}
